// 存放药品相关的数据
export default {

  //开启命名空间，解决不同模块之间成员冲突的问题
  namespaced: true,

  state: {
    //药品信息   dugs数组为table表格的完整数据源
    drugs: [
      { drugID: 'YCP-2024052902', name: "阿莫西林胶囊", size: '24粒/盒', type: '抗生素', OTC: '是', supplierID: 'SY020', price: '30', shelfLife: '3年', day: '2024-5-31  10:00', ShelfID: 'G-8-006', count: '30', status: '库存紧张' },
      { drugID: 'YCP-2024052904', name: "维生素C片", size: '100片/瓶', type: '维生素', OTC: '是', supplierID: 'SY022', price: '15', shelfLife: '2年', day: '2024-5-31  10:00', ShelfID: 'G-10-008', count: '63', status: '库存充足' },
      { drugID: 'YCP-2024052914', name: "非洛地平缓释片", size: '5mg*30片/盒', type: '降压药', OTC: '是', supplierID: 'SY032', price: '55', shelfLife: '2年', day: '2024-5-30  10:00', ShelfID: 'G-20-018', count: '0', status: '无库存' },
      { drugID: 'YCP-2024052906', name: "对乙酰氨基酚片", size: '100片/盒', type: '退烧药', OTC: '是', supplierID: 'SY024', price: '10', shelfLife: '2年', day: '2024-5-31  10:00', ShelfID: 'G-32-010', count: '35', status: '库存紧张' },
      { drugID: 'YCP-2024052907', name: "氯雷他定片", size: '10mg*12片', type: '抗过敏药', OTC: '是', supplierID: 'SY025', price: '40', shelfLife: '2年', day: '2024-5-30  10:00', ShelfID: 'G-13-011', count: '36', status: '库存紧张' },
      { drugID: 'YCP-2024052916', name: "甲硝唑凝胶", size: '10g/支', type: '抗菌药', OTC: '是', supplierID: 'SY034', price: '75', shelfLife: '3年', day: '2024-5-31  10:00', ShelfID: 'G-22-020', count: '80', status: '库存充足' },
      { drugID: 'YCP-2024052908', name: "盐酸雷尼替丁胶囊", size: '30粒/盒', type: '抗酸药', OTC: '是', supplierID: 'SY026', price: '25', shelfLife: '3年', day: '2024-5-31  10:00', ShelfID: 'G-14-012', count: '25', status: '库存紧张' },
      { drugID: 'YCP-2024052909', name: "头孢拉定胶囊", size: '24粒/盒', type: '抗生素', OTC: '否', supplierID: 'SY027', price: '35', shelfLife: '2年', day: '2024-5-31  10:00', ShelfID: 'G-15-013', count: '102', status: '库存充足' },
      { drugID: 'YCP-2024052932', name: "阿司匹林肠溶片", size: '100片/盒', type: '解热镇痛药', OTC: '是', supplierID: 'SY028', price: '15', shelfLife: '3年', day: '2024-5-28  10:00', ShelfID: 'G-16-014', count: '32', status: '库存紧张' },
      { drugID: 'YCP-2024052911', name: "格列齐特片", size: '80mg*60片/盒', type: '降糖药', OTC: '是', supplierID: 'SY029', price: '50', shelfLife: '2年', day: '2024-5-31  10:00', ShelfID: 'G-17-015', count: '230', status: '库存充足' },
      { drugID: 'YCP-2024052921', name: "阿卡波糖片", size: '50mg*30片/盒', type: '降糖药', OTC: '是', supplierID: 'SY039', price: '95', shelfLife: '2年', day: '2024-5-31  10:00', ShelfID: 'G-27-025', count: '46', status: '库存紧张' },
      { drugID: 'YCP-2024052912', name: "奥美拉唑肠溶胶囊", size: '20mg*24粒/盒', type: '抗酸药', OTC: '是', supplierID: 'SY030', price: '45', shelfLife: '2年', day: '2024-5-30  10:00', ShelfID: 'G-18-016', count: '22', status: '库存紧张' },
      { drugID: 'YCP-2024052913', name: "硝酸甘油片", size: '1mg*100片/盒', type: '心绞痛药', OTC: '是', supplierID: 'SY031', price: '60', shelfLife: '3年', day: '2024-5-31  10:00', ShelfID: 'G-19-017', count: '0', status: '无库存' },
      { drugID: 'YCP-2024052942', name: "布洛芬缓释胶囊", size: '24粒/盒', type: '止痛药', OTC: '是', supplierID: 'SY021', price: '35', shelfLife: '2年', day: '2024-5-31  10:00', ShelfID: 'G-9-007', count: '82', status: '库存充足' },
      { drugID: 'YCP-2024052939', name: "硫酸沙丁胺醇吸入气雾剂", size: '100μg*200揿/支', type: '哮喘药', OTC: '是', supplierID: 'SY033', price: '80', shelfLife: '2年', day: '2024-5-31  10:00', ShelfID: 'G-21-019', count: '180', status: '库存充足' },
      { drugID: 'YCP-2024052917', name: "复方丹参滴丸", size: '27mg*180丸/瓶', type: '心血管药', OTC: '是', supplierID: 'SY035', price: '90', shelfLife: '2年', day: '2024-5-30  10:00', ShelfID: 'G-23-021', count: '85', status: '库存充足' },
      { drugID: 'YCP-2024052901', name: "999感冒灵", size: '10g*9袋', type: '感冒药', OTC: '否', supplierID: 'SY019', price: '25', shelfLife: '2年', day: '2024-5-31  10:00', ShelfID: 'G-7-005', count: '100', status: '库存充足' },
      { drugID: 'YCP-2024052905', name: "复方甘草片", size: '100片/盒', type: '咳嗽药', OTC: '是', supplierID: 'SY023', price: '20', shelfLife: '3年', day: '2024-5-30  10:00', ShelfID: 'G-11-009', count: '48', status: '库存紧张' },
      { drugID: 'YCP-2024052918', name: "马来酸曲美布汀胶囊", size: '0.1g*24粒/盒', type: '胃肠动力药', OTC: '否', supplierID: 'SY036', price: '65', shelfLife: '3年', day: '2024-5-31  10:00', ShelfID: 'G-24-022', count: '50', status: '库存充足' },
      { drugID: 'YCP-2024052949', name: "盐酸左西替利嗪片", size: '5mg*14片/盒', type: '抗过敏药', OTC: '是', supplierID: 'SY037', price: '85', shelfLife: '2年', day: '2024-5-30  10:00', ShelfID: 'G-25-023', count: '100', status: '库存充足' },
      { drugID: 'YCP-2024052920', name: "枸橼酸铋钾胶囊", size: '0.11g*40粒/盒', type: '胃药', OTC: '是', supplierID: 'SY038', price: '70', shelfLife: '3年', day: '2024-5-31  10:00', ShelfID: 'G-26-024', count: '65', status: '库存充足' },
      { drugID: 'YCP-2024052937', name: "辛伐他汀片", size: '10mg*7片/盒', type: '调脂药', OTC: '是', supplierID: 'SY040', price: '105', shelfLife: '3年', day: '2024-5-28  10:00', ShelfID: 'G-28-026', count: '14', status: '库存紧张' },
      { drugID: 'YCP-2024052923', name: "米诺地尔溶液", size: '5%*60mL/瓶', type: '生发药', OTC: '是', supplierID: 'SY041', price: '110', shelfLife: '2年', day: '2024-5-31  10:00', ShelfID: 'G-29-027', count: '27', status: '库存紧张' },
      { drugID: 'YCP-2024052903', name: "氟康唑胶囊", size: '5mg*6粒/盒', type: '抗真菌药', OTC: '是', supplierID: 'SY042', price: '85', shelfLife: '3年', day: '2024-5-30  10:00', ShelfID: 'G-30-028', count: '150', status: '库存充足' }],
  },

  getters: {

  },

  mutations: {

    //删除药品
    deleteDugs(state, index) {
      alert('您删除了药品：' + state.drugs[index].name);
      state.drugs.splice(index, 1);
    },

    //更新药品信息
    updateDrugs(state, data) {
      console.log(data);
      if (data.type === 'add')
        state.drugs.unshift(data.data);
      else {
        console.log(data.data.drugID)
        const index = state.drugs.findIndex(item => item.drugID !== data.data.drugID);
        // console.log(index)
        state.drugs.splice(index-1, 1, data.data);
      }
    }

  },

  actions: {
    //data = {data:this.addDrug, type:this.drawerType}
    onSubmit(state, data) {
      state.commit('updateDrugs', data);
    }

  }
}